<?php

/**
 * This is the model class for table "posts".
 *
 * The followings are the available columns in table 'posts':
 * @property string $id
 * @property string $post_model
 * @property string $post_author
 * @property string $post_date
 * @property string $post_content
 * @property string $post_title
 * @property string $post_alias
 * @property string $post_uid
 * @property integer $post_status
 * @property string $seo_title
 * @property string $seo_keywords
 * @property string $seo_description
 * @property integer $comment_status
 * @property string $comment_count
 * @property string $show_num
 */
class Posts extends CActiveRecord {
    public $post_model_array = array(
        'article' => '文档',
        'album' => '相册',
        'download' => '下载',
    );
    
    public $status_array = array(
        0 => '禁用',
        1 => '启用'
    );
    
    public $comment_status_array = array(
        0 => '禁止',
        1 => '允许'
    );
    //资源
    public $post_resources;

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Posts the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return '{{posts}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('post_title, post_uid, post_content, post_alias, category_id', 'required'),
            array('post_status, comment_status', 'numerical', 'integerOnly' => true),
            array('post_alias', 'unique'),
            array('post_model', 'length', 'max' => 8),
            array('post_author, post_title, post_alias, seo_title, seo_keywords', 'length', 'max' => 255),
            array('post_uid, comment_count, show_num', 'length', 'max' => 11),
            array('post_date, post_content, seo_description', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, post_model, post_author, post_date, post_content, post_title, post_alias, post_uid, post_status, seo_title, seo_keywords, seo_description, comment_status, comment_count, show_num', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'post_model' => '文档模型',
            'post_author' => '作者',
            'post_date' => '发布时间',
            'post_content' => '详细内容',
            'post_title' => '标题',
            'post_alias' => '别名',
            'post_uid' => '发布人',
            'post_status' => '状态',
            'seo_title' => 'SEO标题',
            'seo_keywords' => 'SEO关键字',
            'seo_description' => 'SEO描述',
            'comment_status' => '评论',
            'comment_count' => '评论数',
            'show_num' => '浏览量',
            'category_id' => '栏目',
            'post_resources' => '相关附件',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->compare('category_id', $this->category_id);
        $criteria->compare('post_model', $this->post_model);
        $criteria->compare('post_author', $this->post_author, true);
        $criteria->compare('post_date', $this->post_date, true);
        $criteria->compare('post_content', $this->post_content, true);
        $criteria->compare('post_title', $this->post_title, true);
        $criteria->compare('post_alias', $this->post_alias, true);
        $criteria->compare('post_uid', $this->post_uid);
        $criteria->compare('post_status', $this->post_status);
        $criteria->compare('seo_title', $this->seo_title, true);
        $criteria->compare('seo_keywords', $this->seo_keywords, true);
        $criteria->compare('seo_description', $this->seo_description, true);
        $criteria->compare('comment_status', $this->comment_status);
        $criteria->compare('comment_count', $this->comment_count, true);
        $criteria->compare('show_num', $this->show_num, true);
        $criteria->order = 'id DESC';

        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                    'pagination' => array(
                        'pageSize' => 20,
                    )
                ));
    }

}